package com.five.basic.service.impl;


import com.five.basic.mapper.BaseMapper;
import com.five.basic.result.PageList;
import com.five.basic.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


public class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;


    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }

    @Override
    public T queryById(Long id) {
        return baseMapper.queryById(id);
    }

    @Override
    public PageList<T> queryPage(T t) {
        // 查询总条数
        Integer total = baseMapper.queryCount(t);

        if (total == null || total == 0) {
            return new PageList<>();
        }
        // 查询每页数据
        List<T> data = baseMapper.queryPage(t);

        return new PageList<>(total,data);
    }

    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public void deleteBatch(List<Long> ids) {
            baseMapper.deleteBatch(ids);
    }
}
